package de.szut.sudoku.difficulty;

/**
 * Container that contains the current difficulty and all difficulties
 * 
 * @author dqi12huisinga
 * 
 */
public class DifficultyContainer {
	private Difficulty currentDifficulty;
	public final static Difficulty[] difficulties = { (Difficulty) new Easy(),
			(Difficulty) new Medium(), (Difficulty) new Hard() };
	public final static int defaultDifficulty = 1;

	public Difficulty getCurrentDifficulty() {
		return currentDifficulty;
	}

	public void setCurrentDifficulty(Difficulty currentDifficulty) {
		this.currentDifficulty = currentDifficulty;
	}

	/**
	 * Gets a difficulty object from the name
	 * 
	 * @param difficultyName
	 * @return
	 */
	public Difficulty getDifficultyFromName(String difficultyName) {
		// iterates through all difficulties and looks for the name
		for (Difficulty currentDifficulty : difficulties) {
			if (currentDifficulty.getDifficultyName().equals(difficultyName)) {
				return currentDifficulty;
			}
		}
		return null;
	}

	/**
	 * Gets the index of the current difficulty in all difficulties for easier
	 * access
	 * 
	 * @return
	 */
	public int getIndexOfCurrentDifficulty() {
		int index = 0;
		// iterates through all difficulties and checks the pointer
		for (Difficulty difficulty : difficulties) {
			if (difficulty == currentDifficulty) {
				return index;
			}
			index++;
		}
		return -1;
	}

	public DifficultyContainer() {
		currentDifficulty = difficulties[defaultDifficulty];
	}
}
